<template>
  <div id="usermgr" v-loading="loading">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      title="账号信息"
      @del="del"
      @star="star"
      @newCreate="newCreate"
    ></v-tableTitle>
    <GTable
      ref="table"
      :hasCheck="true"
      :hasEdit="true"
      api="/user/{page}"
      :otherHeight="0"
      :columnSource="baseColumns"
      :cbFun="cbFun"
      @selection-change="(data) => (tableSelectData = data)"
      @setdialog="setdialog"
    />
  </div>
</template>

<script>
import tableTitle from "commons/TableTitle";

export default {
  name: "userMgr",
  data() {
    return {
      loading: false,
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
      // compantList: [],
    };
  },
  computed: {
    btnConfig() {
      return [
        {
          label: this.$t("common.create"),
          // certigier: !this.btnPermNameList.includes('EN010101'),
          invalid: "newCreate",
        },
        {
          label: this.$t("common.delete"),
          // certigier: !this.btnPermNameList.includes('EN010102'),
          disabled: true,
          invalid: "del",
        },
        {
          label: this.$t("app.startOrPause"),
          // certigier: !this.btnPermNameList.includes('EN010103'),
          disabled: true,
          invalid: "star",
        },
      ];
    },
    baseColumns() {
      return [
        {
          label: this.$t("common.user"),
          prop: "username",
          input: "input",
        },
        {
          label: this.$t("app.fullname"),
          prop: "fullname",
          input: "input",
        },
        {
          label: this.$t("app.email"),
          prop: "email",
          input: "input",
        },
        {
          label: this.$t("common.status"),
          prop: "status",
          input: "select",
          options: [
            { value: 1, label: "启用" },
            { value: -1, label: "停用" },
          ],
        },
      ];
    },
  },
  methods: {
    getOptions() {
      // this.$post("/v1/edi/plCompany/selectPlCompany", {
      //   pageNum: 1,
      //   pageSize: 999,
      // }).then((res) => {
      //   const data = res.data.item;
      //   this.compantList = data.map((i) => {
      //     i.description = i.companyName;
      //     i.code = i.id;
      //     return i;
      //   });
      // });
    },
    newCreate() {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: "userMgrDeawer" });
    },
    async star(data) {
      let arr = [];
      data.forEach((item) => {
        arr.push(item.username);
      });
      try {
        let res = await this.$api.post(`/user/updatStatus`, arr);
        this.$message.success(res.returnMgr);
        this.getTableData();
      } catch (e) {
        this.$message.error(e);
      }
    },
    //删除
    async del(data) {
      let arr = [];
      data.forEach((item) => {
        arr.push(item.username);
      });
      try {
        let res = await this.$api.post(`/user/delete`, arr);
        this.$message.success(res.returnMgr);
        this.getTableData();
      } catch (e) {
        this.$message.error(e);
      }
    },
    async getTableData() {
      this.$refs.table.getTableData();
    },
    //设置弹框
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: "userMgrDeawer" });
    },
    cbFun(res) {
      return { list: res.data.page.records, total: res.data.page.total }
    },
  },
  mounted() {
    // this.getOptions();
  },
  components: {
    "v-tableTitle": tableTitle,
  },
};
</script>

<style scoped></style>
